import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';

import 'logic.dart';

class BillDetailPage extends StatelessWidget {
  final logic = Get.find<BillDetailLogic>();
  final state = Get.find<BillDetailLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("收入")),
      body: Container(
        margin: const EdgeInsets.fromLTRB(0, 30, 0, 20),
        width: double.infinity,
        child: Column(
          children: [
            _buildIconWidget(),
            _buildLabelWidget(),
            _buildAmountWidget(),
            _buildPayMethodWidget(context),
            _buildDateWidget(),
            _buildTimeWidget(),
            _buildDescWidget(),
            const Spacer(),
            _buildBottomOptionWidget(context),
          ],
        ),
      ),
    );
  }

  Widget _buildIconWidget() {
    return Image.asset(
      "assets/images/logo.png",
      width: 60,
      height: 60,
    );
  }

  Widget _buildLabelWidget() {
    return const Padding(
      padding: EdgeInsets.all(5),
      child: Text(
        "收红包",
        style: TextStyle(
          fontWeight: FontWeight.bold,
          fontSize: 16,
        ),
      ),
    );
  }

  Widget _buildAmountWidget() {
    return const Text(
      "+¥2.00",
      style: TextStyle(
        color: Colors.green,
        fontWeight: FontWeight.bold,
        fontSize: 16,
      ),
    );
  }

  Widget _buildPayMethodWidget(BuildContext context) {
    return Container(
      padding: const EdgeInsets.fromLTRB(10, 3, 10, 3),
      margin: const EdgeInsets.symmetric(vertical: 8),
      decoration: const BoxDecoration(
        color: Colors.blue,
        borderRadius: BorderRadius.all(Radius.circular(5)),
      ),
      child: Text(
        "支付宝",
        style: TextStyle(color: Theme.of(context).colorScheme.onPrimary),
      ),
    );
  }

  Widget _buildDateWidget() {
    return const Text(
      "2023年10月26日",
      style: TextStyle(fontWeight: FontWeight.w500),
    );
  }

  Widget _buildTimeWidget() {
    return const Text(
      "今天 10:20",
      style: TextStyle(fontWeight: FontWeight.w500),
    );
  }

  Widget _buildDescWidget() {
    return const Padding(
      padding: EdgeInsets.symmetric(vertical: 10),
      child: Text(
        "支付宝红包",
        style: TextStyle(fontWeight: FontWeight.w500),
      ),
    );
  }

  Widget _buildBottomOptionWidget(BuildContext context) {
    return Container(
      width: 200,
      height: 60,
      padding: const EdgeInsets.symmetric(horizontal: 20),
      decoration: BoxDecoration(
        color: Theme.of(context).colorScheme.onPrimary,
        borderRadius: const BorderRadius.all(Radius.circular(35)),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          _buildOptionBtnWidget(Icons.delete, "删除", () {
            // 删除后无法回退,确认要删除吗?
            deleteDialog();
          }),
          _buildOptionBtnWidget(Icons.copy, "复制", () {}),
          _buildOptionBtnWidget(Icons.replay, "退款", () {}),
          _buildOptionBtnWidget(Icons.edit, "编辑", () {}),
        ],
      ),
    );
  }

  void deleteDialog() {
    SmartDialog.show(builder: (context) {
      return AlertDialog(
        title: const Text('删除'),
        content: const Text('删除后无法回退,确认要删除吗?'),
        actionsPadding: const EdgeInsets.all(10),
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
        actions: [
          TextButton(
            child: const Text('取消'),
            onPressed: () {
              SmartDialog.dismiss();
            },
          ),
          TextButton(
            child: const Text('确定'),
            onPressed: () {
              SmartDialog.dismiss();
            },
          ),
        ],
      );
    });
  }

  Widget _buildOptionBtnWidget(IconData icon, String data, GestureTapCallback? onTap) {
    return GestureDetector(
      onTap: onTap,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Icon(icon),
          Text(data),
        ],
      ),
    );
  }
}
